@extends("admin.base.base")
@section("title")
    <title>问答列表</title>
    <link href="{{ asset('css/admin/css/paginate.css') }}" rel="stylesheet">
@endsection
@section('content')
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 评论管理 <span class="c-gray en">&gt;</span> 问答列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
    <div class="text-c" style="text-align: right">
        <form action="{{url('admin/search-problem')}}" method="post">
            <input type="text" name="keywords" id="" placeholder=" 你想要搜索的问题" style="width:250px" class="input-text">
            {{csrf_field()}}
            <button name="" id="" class="btn btn-success" type="submit"><i class="Hui-iconfont">&#xe665;</i> 搜问题</button>
        </form>
    </div>
    <div class="cl pd-5 bg-1 bk-gray mt-20">
        {{--<a class="btn btn-primary radius" data-href="" data-title="已审核列表" href="{{url('admin/success-base')}}"> 已审核列表</a>--}}
        <span class="r">共有问题：<strong>{{$topics->total()}}</strong> 条</span>
    </div>
    <div class="mt-20">
        <table class="table table-border table-bordered table-bg table-hover table-sort">
            <thead>
            <tr class="text-c">
                <th width="20"><input name="" type="checkbox" value=""></th>
                <th width="20">ID</th>
                <th width="100">问题</th>
                <th width="100">内容</th>
                <th width="70">作者</th>
                <th width="50">创建时间</th>
                <th width="30">操作</th>
            </tr>
            </thead>
            <tbody>
            @foreach($topics as $topic)
                <tr class="text-c">
                    <td><input name="" type="checkbox" value=""></td>
                    <td>{{$topic->id}}</td>
                    <td>{{$topic->title}}</td>
                    <td>{{$topic->body}}</td>
                    <td>
                        <img src="{{$topic->user->avatar}}" width="40px" height="40px">
                        {{$topic->user->name}}
                    </td>
                    <td>{{$topic->created_at}}</td>
                    <td class="td-manage"> <a style="text-decoration:none" class="ml-5" onClick="Topic_show('查看问题','{{url('admin/topics/'.$topic->id)}}','{{$topic->id}}')" href="javascript:;" title="查看"><i class="Hui-iconfont">&#xe665;</i></a> <a style="text-decoration:none" class="ml-5" onClick="topic_del(this,'{{$topic->id}}')" href="javascript:;" title="删除"><i class="Hui-iconfont">&#xe6e2;</i></a></td>
                </tr>
            @endforeach
            {{csrf_field()}}
            {{method_field('DELETE')}}
            </tbody>
        </table>
        <div class="panel-body">
            {!! $topics->render() !!}
        </div>
    </div>
</div>
@endsection
@section("js")
    <script type="text/javascript">
        /*图片-查看*/
        function Topic_show(title,url,id){
            var index = layer.open({
                type: 2,
                title: title,
                content: url
            });
            layer.full(index);
        }

        /*图片-删除*/
        function topic_del(obj,id){
            layer.confirm('确认要删除吗？',function(index){
                $.ajax({
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    },
                    type: 'POST',
                    method: 'DELETE',
                    url: '{{url('admin/topics')}}'+'/'+id,
                    data:{'_token':'{{csrf_token()}}'},
                    dataType: 'json',
                    success: function(data){
                        if (data.code == 0){
                            $(obj).parents("tr").remove();
                            layer.msg(data.msg,{icon:1,time:1000});
                        }else {
                            layer.msg(data.msg);
                        }
                    }
                });
            });
        }
    </script>
@endsection